package tag;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class ForEachTag extends SimpleTagSupport {

    private String var;
    private String items[];

    public String getVar() {
        return var;
    }

    public void setVar(String var) {
        this.var = var;
    }

    public String[] getItems() {
        return items;
    }

    public void setItems(String[] items) {
        this.items = items;
    }

    @Override
    public void doTag() throws JspException, IOException {
        if (items != null && items.length > 0) {
            JspContext jspContext = this.getJspContext();
            for (int i = 0; i < items.length; i++) {
                jspContext.setAttribute(var, items[i]);
                this.getJspBody().invoke(null);
            }
        }
    }
}



